#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
	int p=0;
	int q;
	int syn;
	printf("输入:\n");
	char ch[100];
	gets(ch);
	char *key[6]={"begin","if","then","while","do","end"};
	p = 0;
	printf("输出:\n");
	do{
		char token[100] = {};
		q = 0;
		while(ch[p] == ' ')p++;
		if((ch[p] >= 'a' && ch[p] <='z') || (ch[p] >= 'A' && ch[p] <= 'Z')){
			token[q++] = ch[p];
			p++;
			while ((ch[p] >= '0' && ch[p] <= '9')||(ch[p]>='a' && ch[p]<='z')||(ch[p]>='A'&&ch[p] <='Z')) {
				token[q++] = ch[p++];
			}
			syn = 10;
			token[q] = '\0';
			for(int n=0;n<6;n++){
				if(strcmp(token, key[n]) == 0){
					syn = n+1;
					break;
				}
			}
		}
		else if(ch[p] >= '0' && ch[p] <='9'){
			token[q++] = ch[p];
			while(ch[p] >= '0' && ch[p]<='9')
			token[q++] = ch[p++];
			syn = 11;
		}
		else switch (ch[p]) {
			case '<':token[q++] = ch[p++];
				if(ch[p] == '>'){
					syn = 21;
					token[q++] = ch[p++];
				}
				else if(ch[p] == '='){
					syn = 22;
					token[q++] = ch[p++];
				}
				else syn = 23;
				break;
			case '>':token[q++] = ch[p++];
				if(ch[p] == '>'){
					syn = 24;
					token[q++] = ch[p++];
				}
				else syn = 20;
				break;
			case ':':token[q++] = ch[p++];
				if(ch[p] == '='){
					syn = 18;
					token[q++] = ch[p++];
				}
				else syn = 17;
				break;
			case '*':syn = 13;
				token[q++] = ch[p++];
				break;
			case '/':syn = 14;
				token[q++] = ch[p++];
				break;
			case '+':syn = 15;
				token[q++] = ch[p++];
				break;
			case '-':syn = 16;
				token[q++] = ch[p++];
				break;
			case '=':syn = 25;
				token[q++] = ch[p++];
				break;
			case ';':syn = 26;
				token[q++] = ch[p++];
				break;
			case '(':syn = 27;
				token[q++] = ch[p++];
				break;
			case ')':syn = 28;
				token[q++] = ch[p++];
				break;
			case '#':syn = 0;
				token[q++] = ch[p++];
				break;
			case '\n':syn = -2;
				token[q++] = ch[p++];
				break;
			default:syn = -1;
		}
		switch (syn) {
			case -1:printf("Error!\n");
				break;
			default:printf("(%d,%s)\n",syn,token);
		}
	}while (syn > 0);{
		return 0;
	}
}